<?php
	defined('_JEXEC') or die('Restricted access');

	$model = $this->data['model'];
	$search = $this->data['search'];

	$lim	= JRequest::getVar('limit', 0, '', 'int');
	$lim0	= JRequest::getVar('limitstart', 0, '', 'int');
	jimport('joomla.html.pagination');
	$pageNav = new JPagination( $search['count'], $lim0, $lim );

?>
<h1>База данных по моторам</h1>
<h2>Подбор ВМГ</h2>
<div class="rcbase_content">
	<div style="text-align:right;">
	</div>
	<form action="/?option=com_rcbase&view=motorlist&task=search" method="get" enctype="multipart/form-data">
		<input type="hidden" name="option" value="com_rcbase"/>
		<input type="hidden" name="view" value="motorlist"/>
		<input type="hidden" name="task" value="search"/>
		<input type="hidden" name="limit" value="10"/>
		<div id="rcbase_formtabs">
			<ul>
				<li><a href="#form-1">По параметрам</a></li>
				<li><a href="#form-2">Под модель</a></li>
				<li><a href="#form-3">Под винт</a></li>
			</ul>
			<div id="form-1">
				<table class="table">
					<tr>
						<th>Вес мотора (г)</th>
						<td>
							от <input type="text" name="weight_from" value="<?= $search['param']['weight_from'] ? $search['param']['weight_from'] : '' ?>" size="5" maxlength="4"/>
							до <input type="text" name="weight_to" value="<?= $search['param']['weight_to'] ? $search['param']['weight_to'] : '' ?>" size="5" maxlength="4"/>
						</td>
					</tr>
					<tr>
						<th>Обороты (KV)</th>
						<td>
							от <input type="text" name="kv_from" value="<?= $search['param']['kv_from'] ? $search['param']['kv_from'] : '' ?>" size="5" maxlength="4"/>
							до <input type="text" name="kv_to" value="<?= $search['param']['kv_to'] ? $search['param']['kv_to'] : '' ?>" size="5" maxlength="4"/>
						</td>
					</tr>
					<tr>
						<th>АКБ (банок)</th>
						<td>
							от <input type="text" name="cells_from" value="<?= $search['param']['cells_from'] ? $search['param']['cells_from'] : '' ?>" size="5" maxlength="1"/>
							до <input type="text" name="cells_to" value="<?= $search['param']['cells_to'] ? $search['param']['cells_to'] : '' ?>" size="5" maxlength="1"/>
						</td>
					</tr>
					<tr>
						<th>Ток (А)</th>
						<td>
							от <input type="text" name="current_from" value="<?= $search['param']['current_from'] ? $search['param']['current_from'] : '' ?>" size="5" maxlength="3"/>
							до <input type="text" name="current_to" value="<?= $search['param']['current_to'] ? $search['param']['current_to'] : '' ?>" size="5" maxlength="3"/>
						</td>
					</tr>
					<tr>
						<th>Тяга (г)</th>
						<td>
							от <input type="text" name="power_from" value="<?= $search['param']['power_from'] ? $search['param']['power_from'] : '' ?>" size="5" maxlength="4"/>
							до <input type="text" name="power_to" value="<?= $search['param']['power_to'] ? $search['param']['power_to'] : ''?>" size="5" maxlength="4"/>
						</td>
					</tr>
					<tr>
						<th colspan="2">
							<input type="submit" name="param_submit" value="&nbsp;&nbsp;Подобрать&nbsp;&nbsp;"/>
						</th>
					</tr>
				</table>
			</div>
			<div id="form-2">
				<table class="table">
					<tr>
						<th>Тип модели</th>
						<td>
							<select name="model_type">
								<option value="1"<?= $search['param']['model_type'] == '1' ? ' selected' : '' ?>>Тренер</option>
								<option value="2"<?= $search['param']['model_type'] == '2' ? ' selected' : '' ?>>Копия (полукопия)</option>
								<option value="3"<?= $search['param']['model_type'] == '3' ? ' selected' : '' ?>>Пилотажка</option>
								<option value="4"<?= $search['param']['model_type'] == '4' ? ' selected' : '' ?>>3D</option>
							</select>
						</td>
					</tr>
					<tr>
						<th>Вес модели (г)</th>
						<td>
							<input type="text" name="weight" value="<?= $search['param']['weight'] ? $search['param']['weight'] : '' ?>" size="5" maxlength="4"/>
						</td>
					</tr>
					<tr>
						<th colspan="2">
							<input type="submit" name="model_submit" value="&nbsp;&nbsp;Подобрать&nbsp;&nbsp;"/>
						</th>
					</tr>
				</table>
			</div>
			<div id="form-3">
				<table class="table">
					<tr>
						<th>Диаметр (дюйм)</th>
						<td>
							<input type="text" name="prop_d" value="<?= $search['param']['prop_d'] ? $search['param']['prop_d'] : '' ?>" size="5" maxlength="2"/>
						</td>
					</tr>
					<tr>
						<th>Шаг (дюйм)</th>
						<td>
							<input type="text" name="prop_h" value="<?= $search['param']['prop_h'] ? $search['param']['prop_h'] : '' ?>" size="5" maxlength="2"/>
						</td>
					</tr>
					<tr>
						<th colspan="2">
							<input type="submit" name="prop_submit" value="&nbsp;&nbsp;Подобрать&nbsp;&nbsp;"/>
						</th>
					</tr>
				</table>
			</div>
		</div>
		<script language="JavaScript" type="text/javascript">
			jQuery('#rcbase_formtabs').tabs({ selected: <?= $search['form'] ?> });
		</script>
	</form>
	<?php if ($search['count']): ?>
	<h3>Найдено записей: <?= $search['count'] ?></h3>
		<table class="table">
			<tr>
				<th colspan="6">Мотор</th>
				<th>KV</th>
				<th>Вес (г)</th>
			</tr>
			<tr>
				<th>Автор</th>
				<th>Винт</th>
				<th>АКБ</th>
				<th>Ток (А)</th>
				<th>Напр (В)</th>
				<th>Мощ. (Вт)</th>
				<th>Тяга (г)</th>
				<th>Рейтинг</th>
			</tr>
			<?php foreach ($search['result'] as $row): ?>
				<?php if ($motor_id != $row['motor_id']): ?>
					<?php
						$motor_id = $row['motor_id'];
						$tester = $model->getMotorTester($motor_id);
					 ?>
					<tr>
						<td colspan="6" align="left">
							<a href="/?option=com_rcbase&view=motor&task=motor&id=<?= $row['motor_id'] ?>">
								<strong><?= $row['title'] ?></strong></td>
							</a>
						<td align="center"><strong><?= $row['kv'] ?></strong></td>
						<td align="center"><strong><?= $row['weight'] ?></strong></td>
					</tr>
				<?php endif; ?>
				<tr>
					<td><?= $tester[$row['test_user_id']]['username'] ?></td>
					<td><?= $row['prop_type'] ?> <?= $row['prop_d'] ?>X<?= $row['prop_h'] ?></td>
					<td align="right"><?= $row['cells'] ?>S</td>
					<td align="right"><?= $row['current'] ?></td>
					<td align="right"><?= ($row['voltage'] * 1) > 0 ? $row['voltage'] : '~'.(3.7 * $row['cells']) ?></td>
					<td align="right"><?= ($row['voltage'] * 1) > 0 ? $row['voltage'] * $row['current'] : '~'.(3.7 * $row['cells'] * $row['current']) ?></td>
					<td align="right"><?= $row['power'] ?></td>
					<td align="right">

						<span style="color:green;">
							<a href="/?option=com_rcbase&view=motortest&task=rateup&mid=<?= $row['motor_id'] ?>&id=<?= $row['id'] ?>">&uArr;</a>
							<?= $row['test_rate_up'] ? count(explode('|', $row['test_rate_up'])) : '0' ?>
						</span>
						/
						<span style="color:red;">
							<a href="/?option=com_rcbase&view=motortest&task=ratedown&mid=<?= $row['motor_id'] ?>&id=<?= $row['id'] ?>">&dArr;</a>
							<?= $row['test_rate_down'] ? count(explode('|', $row['test_rate_down'])) : '0' ?>
						</span>


					</td>
				</tr>
			<?php endforeach; ?>
		</table>
	<?php endif; ?>
	<div><?= $pageNav->getListFooter(); ?></div>
		<script language="JavaScript" type="text/javascript">
			jQuery('.limit').hide();
			jQuery('#limit').attr("disabled","disabled");
		</script>
	<!--h3>SQL</h3>
	<p><?= $search['sql'] ?></p-->
</div>
